<style lang="scss" scoped>
	.content {

		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.largebtn {
		width: 690rpx;
		height: 88rpx;
		background: #ffffff;
		border: 2rpx solid #409eff;
		border-radius: 46rpx;

	}

	.nav {
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		padding-bottom: 10rpx;
		border-bottom: 1px solid #dee2ee;
		background-color: white;
		z-index: 999;
	}

	.top {
		padding: 20rpx 30rpx;
	}

	.search {
		width: 554rpx;
		height: 76rpx;
		background: #f4f5f7;
		border: 2rpx solid #f5f5f5;
		border-radius: 46rpx;
		padding: 20rpx;

		.ipt {
			flex: 1;
		}
	}


	.lists {
		margin-bottom: 50rpx;

		.list {
			width: 690rpx;

			opacity: 1;
			background: #ffffff;
			border-radius: 20rpx;
			box-shadow: 0rpx 30rpx 18rpx -14rpx #e6ebf2;
			overflow: hidden;
			margin-top: 30rpx;

			.head {
				width: 100%;
				border-bottom: 1px solid #f5f7fa;

				.tips {

					.tip {
						width: 346rpx;
						height: 68rpx;
						border-radius: 0 34rpx 34rpx 0;
						color: #98A5B3;
					}

					.actived {
						background: rgba($color: #07c160, $alpha: 0.1);


					}
				}


			}

			.contains {
				width: 100%;
				padding: 20rpx;

				.text {
					width: 620rpx;
					line-height: 60rpx;

				}
			}


		}
	}

	.line {
		>view {
			width: 50%;
		}
	}

	.progressbox {
		padding: 20rpx;
		border-top: 2rpx solid #f5f7fa;

		.line2 {
			width: 100%;

			.progress {
				width: 600rpx;
				transform: translateY(-8rpx);
				margin-right: 20rpx;
			}

			.row1 {
				width: 100%;
			}
		}
	}

	.btns {
		height: 100rpx;
		justify-content: flex-end;

		padding: 20rpx;

		.btn {
			width: 150rpx;
			height: 68rpx;

			border-radius: 36rpx;
			margin-left: 50rpx;
		}

	}
</style>

<template>
	<view class="content">
		<view class="nav bgwhite" id="nav">
			<Search placeholder="搜索任务名称/关键字" v-model="keywords" @onConfirm="search" :iconType="CustomIconName.Add"    @onIcon="$navTo(PagesTaskRouterConfig.Add)"></Search>
			<u-tabs :list="nav" :is-scroll="false" bar-width="60" bar-height="4" :current="current" @change="change">
			</u-tabs>
			<view v-if="current==1" class="center-flex" style="border-top: 1px solid #eee;height:148rpx;">
				<view v-if="!showRadio" class="largebtn center-flex blue bold f34" @click="showRadio=true;orderNum='';">
					批量通过
				</view>
				<view style="width: 100%;padding:0 20rpx;" v-else class="between-flex">
					<view class="blue f28 bold p-left20" @click="showRadio=false;orderNum='';">退出</view>
					<view class="btns f28 align-flex">
						<view style="border:1px solid #409eff;" class="btn cfff center-flex blue" @click="chooseAll">全选
						</view>

						<view class="btn bgblue cfff center-flex" @click="accpetAll()">通过</view>

					</view>

				</view>
			</view>
		</view>
		<view v-if="navheight">
			<view :style="'height:'+navheight+'px;'"></view>

			<view v-if="current==1" style="height:148rpx;"></view>
			<checkbox-group name="" @change="chooseOrder">
				<view class="lists">
					<view class="list" v-for="item,index in list" :key="index">
						<view class="head between-flex">
							<view class="tips" v-if="current!=1">
								<view class="tip f28 center-flex  actived">
									完成进度：{{item.compRate}}%
								</view>
							</view>
							<view v-else class="gray f26 " style="padding:20rpx;">完成进度：{{item.compRate}}%</view>
							<view class="f26 gray p-right20 bold" v-if="!showRadio" :style="{color:$filterState(item.states).color}">{{$filterState(item.states).name }}
							</view>
							<view v-else>
								<label class="radio p-right20">
									<checkbox color="#409eff" :checked="taskids.indexOf(item.id)!=-1" :value="item.id" />
								</label>
							</view>
						</view>
						<view class="contains between-flex" @click="$navTo(PagesTaskRouterConfig.TaskDetail+'?id='+item.id)">
							<view class="text">
								<view class="textColor f34 bold">{{item.taskName}}</view>
								<view class="align-flex">
									<view class="gray " style="width:125rpx;">负责人 </view><span class="textColor">{{item.leaderUser | users}}</span>
								</view>
								<view class="align-flex" v-if="item.itemCode">
									<view class="gray " style="width:125rpx;">所属项目 </view><span class="textColor">{{item.itemCode}}</span>
								</view>
								<view class="align-flex">
									<view class="gray " style="width:125rpx;">需求时间 </view><span class="textColor">{{item.planEndDate}}</span>
								</view>

							</view>
							<u-icon name="arrow-right" color="#98a5b3" size="28"></u-icon>
						</view>
						<view class="progressbox" v-if="current!=1">
							<view class="between-flex" v-if="item.taskChild.length==0">
								<view class="f28 gray">无子任务</view>
								<view class="blue" @click="$navTo(PagesTaskRouterConfig.AddChild+'?id='+item.id)">
									去添加<u-icon name="arrow-right" color="#409EFF" size="28"></u-icon>
								</view>
							</view>
							<view v-else class="between-flex" @click="showChild(index)">
								<view class="f28 gray">子任务进度({{item.taskChild.length}})</view>
								<view :style="item.flag?'transform: rotate(-180deg);':'' ">
									<u-icon name="arrow-down" color="#409EFF" size="28"></u-icon>
								</view>
							</view>
							<view v-if="item.flag">
								<view class="line2 m-top30" v-for="item2,index2 in item.taskChild" :key="index2">
									<view>{{item2.taskName}}</view>
									<view class="gray align-flex">
										<view class="progress">
											<u-line-progress height="8" :show-percent="false" :active-color="index2%3==0?'#07c160':index2%3==1?'#ebb917;':'#409EFF'" :percent="item2.compRate"></u-line-progress>
										</view> <span class="textColor">{{item2.compRate}}%</span>
									</view>
								</view>

							</view>
						</view>
						<view class="btns f28 align-flex" v-if="!showRadio&&current==1">
							<view @click="rejectOrder(index)" style="border:2rpx solid #dee2ee;" class="btn textColor cfff center-flex ">驳回</view>
							<view @click="accpetOrder(index)" class="btn blue cfff center-flex" style="border:2rpx solid #409eff;">通过</view>
						</view>
					</view>
					<view class="center-flex c999 f24" v-if="nomore">-没有更多了-</view>
					<view v-if="empty" style="position: fixed;top:40%;left:50%;transform: translateX(-50%);">
						<u-empty text="暂无列表"></u-empty>

					</view>
				</view>
			</checkbox-group>
		</view>

		<u-popup border-radius="24" mode="bottom" v-model="showPopup" :closeable="true">
			<notpass @submit="showPopup=false;reset()" :taskid="taskid"></notpass>
		</u-popup>

	</view>


</template>

<script>
	import notpass from '@/pagesTask/operation/notpass.vue'
	import PagesTaskRouterConfig from '@/pagesTask/routerConfig.js'
	import Search from '@/components/input/index.vue'
		import CustomIconName from '@/common/customIconFontName.js'

	export default {
		components: {
			notpass,
			Search
		},
		data() {
			return {
				CustomIconName,
				PagesTaskRouterConfig,
				navheight: 0,
				head: this.$head,
				nav: [{
						name: '待我处理',
						count: 0,
						state: 6
					}, {
						name: '待我审核',
						count: 0,
						state: 2
					},
					{
						name: '我创建的',
						count: 0,
						state: 3

					}
				],
				current: 0,
				showPopup: false,
				flag: false,
				taskids: [], //批量审核
				taskid: '', //单个审核
				showRadio: false,
				page: 1,
				list: [],
				nomore: false,
				empty: false,
				keywords: '',

			}
		},
		onLoad() {

			setTimeout(() => {
				let info = uni.createSelectorQuery().select("#nav");
				info.boundingClientRect((data) => {

					this.navheight = data.height

					// console.log(this.navheight)
				}).exec()

			}, 700)


		},
		onShow() {
			this.reset()

		},
		onReachBottom() {
			if (!this.nomore) {
				this.page++
				this.getlist()
			}
		},
		methods: {
			rejectOrder(index) {
				this.taskid = this.list[index].id
				this.showPopup = true
			},
			accpetOrder(index) {
				this.taskid = this.list[index].id
				uni.showModal({
					title: '确认通过审核吗？',
					success: (res) => {
						if (res.confirm) {

							this.$pop.ajaxPost('/bus/taskInfo/audit', {
								taskId: this.taskid,
								reason: '',
								type: 1
							}).then(res => {
								if (res.code == 0) {
									this.$msg('通过成功')
									this.reset()

								}
							})

						}
					}
				})
			},
			chooseOrder(e) {

				this.taskids = e.detail.value
				console.log(this.taskids)
			},

			accpetAll() {
				if (this.taskids.length == 0) {
					this.$msg('未选择任务')
					return
				}
				uni.showModal({
					title: '确认批量通过审核吗？',
					success: (res) => {
						if (res.confirm) {
							var num = 0
							var length = this.taskids.length
							this.taskids.forEach(item => {
								this.$pop.ajaxPost('/bus/taskInfo/audit', {
									taskId: item,
									reason: '',
									type: 1
								}).then(res => {
									if (res.code == 0) {
										num++
										if (num == length) {
											this.$msg('通过成功')
											this.reset()
										}

									}
								})
							})

						}
					}
				})
			},
			chooseAll() {
				var list = this.taskids

				if (list.length == this.list.length) {
					this.taskids = []
				} else {
					var arr = []
					this.list.forEach(item => {
						arr.push(item.id)
					})
					this.taskids = arr
				}
				console.log(this.taskids)
			},
			search() {
				this.$u.debounce(this.reset, 500)

			},
			reset() {
				this.$showloading()
				this.page = 1
				this.list = []
				this.nomore = false
				this.getlist()
				this.getRedInfo()
			},
			getlist() {

				this.$pop.ajaxPost('/bus/taskInfo/list', {
					taskName: this.keywords,
					pageNum: this.page,
					pageSize: 10,
					states: this.nav[this.current].state
				}).then(res => {
					uni.hideLoading()
					var list = res.body.list

					this.list = this.list.concat(list)

					if (this.list.length == 0) {
						this.empty = true
					} else {
						this.empty = false
						if (list.length < 10) {
							this.nomore = true
						} else {
							this.nomore = false
						}
					}
					this.list.forEach(item => {
						if (!item.taskChild) {
							this.$pop.ajaxPost('/bus/taskInfo/details', {
								id: item.id
							}).then(res2 => {

								if (res2.body.taskChild) {
									item.taskChild = res2.body.taskChild || []

								}
								// this.$forceUpdate()

							})
						}
					})
				})
			},

			change(index) {

				this.current = index;
				this.reset()
			},


			getRedInfo() {
				this.$pop.ajaxPost('/bus/taskInfo/stats').then(res => {
					this.nav[0].count = res.body.unProcess
					this.nav[1].count = res.body.audit
					this.nav[2].count = res.body.create
				})

			},
			isEnd(item) {

				var endTime = (new Date(item.endTime).getTime())
				var nowTime = new Date().getTime()
				console.log(endTime - nowTime)
				if (nowTime < endTime) {
					return false
				} else {
					return true
				}


			},
			showChild(index) {
				if (this.list[index].flag) {
					this.list[index].flag = false
				} else {
					this.list[index].flag = true
				}
				this.$forceUpdate()
			},

		}
	}
</script>
